home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 019a / view002.zip / VIEW.H < prev    next >
C/C++ Source or Header  |  1991-09-14  |  11KB  |  315 lines

  1. /*
  2. View 0.01 - A simple,small,windowed, text file viewer.
  3.  
  4. Copyright (c) 1991 James P. Goodwin.
  5. All rights reserved.
  6.  
  7. Redistribution and use in source and binary forms are per-
  8. mitted provided that the above copyright notice is dupli-
  9. cated in all such forms and that any documentation,
  10. advertising materials, and other materials related to such
  11. distribution and use acknowledge that the software was
  12. developed by James P. Goodwin.
  13.  
  14. THE SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS
  15. OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE
  16. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PAR-
  17. TICULAR PURPOSE.
  18. */
  19.  
  20.  
  21. /*
  22.   Undefine min and max, I'm going to substitute functions for them
  23.   since I only use integers.
  24. */
  25.  
  26. #ifdef min
  27. #undef min
  28. #endif
  29.  
  30. #ifdef max
  31. #undef max
  32. #endif
  33.  
  34. /*
  35.   The following defines turn off specific features of the view program
  36.   some of these features are interdependant so you may have to turn off
  37.   more than one or turn on more than one to get the effect you are looking
  38.   for.
  39. */
  40. #define VIEW_HAS_RAW         1                   /* Hex and Bin modes */
  41. #define VIEW_HAS_MEMORY      1                   /* Views memory as file */
  42. #define VIEW_HAS_DIR         1                   /* Shows dir listing */
  43. #define VIEW_HAS_SEARCH      1                   /* Search for text string */
  44. #define VIEW_HAS_GOTO        1                   /* Goto line/pos/address */
  45. #define VIEW_HAS_NEWFILE     1                   /* Select a new file while in view */
  46. #define VIEW_HAS_TILE        1                   /* Tile windows when window added or deleted */
  47.  
  48. #define TRUE  1
  49. #define FALSE 0
  50.  
  51. /*
  52.   These defines are for the keyboard scan codes, these are specific to the
  53.   IBM-PC and can be found in the IBM-PC Technical Reference Manual
  54. */
  55. #define CURSOR_DOWN         80
  56. #define CURSOR_LEFT         75
  57. #define CURSOR_RIGHT        77
  58. #define CURSOR_UP           72
  59.  
  60. #define CNTL_CURSOR_LEFT   115
  61. #define CNTL_CURSOR_RIGHT  116
  62. #define CNTL_PGUP          132
  63. #define CNTL_PGDN          118
  64. #define CNTL_HOME          119
  65. #define CNTL_END           117
  66.  
  67. #define PGDN                81
  68. #define PGUP                73
  69. #define HOME                71
  70. #define END                 79
  71.  
  72. #define SHIFT_TAB           15
  73. #define TAB                  9
  74. #define ESC                 27
  75. #define BACKSPACE            8
  76. #define RETURN              13
  77.  
  78. /*
  79.   These are the four ways that the viewstack can be refreshed on the
  80.   screen.
  81. */
  82.  
  83. #define REFRESH_ALL        0             /* Undo all windows, Redo all windows */
  84. #define REFRESH_TOP        1             /* Undo top window, Redo top window */
  85. #define REFRESH_CONTENTS   2             /* Redo contents of top window */
  86. #define REFRESH_OFF        3             /* Undo all windows */
  87. #define REFRESH_NEXT       4
  88. #define REFRESH_PREV       5
  89.  
  90. /*
  91.   These are the ways that the text can scroll vertically
  92. */
  93. #define SCROLL_NONE         0
  94. #define SCROLL_DOWN         1
  95. #define SCROLL_UP           2
  96. #define SCROLL_PAGE_UP      3
  97. #define SCROLL_PAGE_DOWN    4
  98. #define SCROLL_HOME         5
  99. #define SCROLL_END          6
  100. #define SCROLL_RESET        7
  101. #define SCROLL_CLEAR        8
  102.  
  103.  
  104. /*
  105.   These are defines for the limits of various parts of view
  106. */
  107. #define VIEW_MAX_LINE    264             /* Maximum logical "line" (bytes)*/
  108. #define VIEW_MAX_BINMODE 80              /* Maximum logical "line" in BINMODE (bytes)*/
  109. #define VIEW_MAX_HEXMODE 16              /* Maximum logical "line" in HEXMODE (bytes)*/
  110. #define VIEW_MAX_LONG    20              /* Maximum number of digits in ULONG as ascii */
  111. #define VIEW_BUF_SIZE    20480           /* Buffering factor */
  112. #define VIEW_LINE_VIEW   50              /* Number of lines to cache */
  113.  
  114. #define VIEW_EOF         (0xFFFF)        /* VIEWFILE end of file indicator */
  115.  
  116. #if VIEW_HAS_MEMORY
  117.  
  118. #define VIEW_MEM_NAME    "MEMORY"        /* Special file name to indicate memory instead of file */
  119.  
  120. #endif
  121.  
  122. #if VIEW_HAS_DIR
  123.  
  124. #define VIEW_DIR_WIDTH   (view_cols/2)+4            /* Width of directory window */
  125. #define VIEW_DIR_HEIGHT  (view_rows/2)+4            /* Height of directory window */
  126. #define VIEW_DIR_ROW     ((view_rows/2)-(VIEW_DIR_HEIGHT+2)/2) /* Top row of directory window */
  127. #define VIEW_DIR_COL     ((view_cols/2)-(VIEW_DIR_WIDTH+2)/2)  /* Left col of directory window */
  128.  
  129. #endif
  130.  
  131. /*
  132.   These are some types that are used in view
  133. */
  134.  
  135. typedef unsigned long ULONG;             /* an unsigned long just an alias */
  136. typedef unsigned char UCHAR;             /* an unsigned char type */
  137. typedef unsigned int  UINT;              /* an unsigned int type */
  138.  
  139.  
  140.                                          /* Struct to save screen regions in */
  141. typedef 
  142.   struct viewsave
  143.     {
  144.     int row,col,rows,cols;               /* Coordinates and dimensions of region */
  145.     UCHAR *buf;                          /* Data saved from that region */
  146.     } VIEWSAVE;
  147.  
  148.                                          /* Struct for file buffering and control */
  149. typedef
  150.    struct viewfile
  151.      {
  152.      UCHAR *fname;                       /* file name */
  153.      int   fh;                           /* file handle or VIEW_MEM_HDL */
  154.      ULONG pos;                          /* position of "memory" or file pointer */
  155.      ULONG end;                          /* end of the file */
  156.      int   idx;                          /* next character in buffer */
  157.      int   len;                          /* number of characters in buffer */
  158.      UINT  lmode;                        /* formatting mode for lines */
  159.      UCHAR buf[VIEW_BUF_SIZE];           /* buffer */
  160.      } VIEWFILE;
  161.  
  162. typedef                                  /* Struct for managing views on screen */
  163.   struct view
  164.     {
  165.     int         row,col,rows,cols;       /* Current position and dimensions of view */
  166.     int         coff;                    /* column offset into each line */
  167.     ULONG       pos[VIEW_LINE_VIEW];     /* position in viewfile of lines */
  168.     UCHAR       *lines[VIEW_LINE_VIEW];  /* lines currently in view */
  169.     VIEWFILE    *vf;                     /* file control struct for this view */
  170.     VIEWSAVE    *save;                   /* screen region covered by view */
  171.     struct view *next;                   /* next view in chain (circular) */
  172.     struct view *prev;                   /* prev view in chain (circular) */
  173.     } VIEW;
  174.  
  175. #if VIEW_HAS_DIR
  176.  
  177. typedef                                  /* Struct for directory list */
  178.   struct dirlist
  179.     {
  180.     UCHAR *line;                         /* text line for directory list */
  181.     struct dirlist *prev;                /* prev line (NULL terminated)  */
  182.     struct dirlist *next;                /* next line (NULL terminated)  */
  183.     } DIRLIST;
  184.  
  185. #endif
  186.  
  187. extern VIEW *viewstack;                  /* pointer to the bottom view on screen */
  188.  
  189. extern UCHAR _far *screen;               /* pointer to display ram */
  190.  
  191. #if VIEW_HAS_MEMORY
  192. #define VIEW_MEM_HDL -1
  193.                                          /* huge 0 pointer to memory */
  194. extern UCHAR _huge *memory;
  195. #endif
  196.                                          /* characters used in hex/dec conversion routines */
  197. extern UCHAR  hexdigits[];
  198.  
  199. extern int view_offset;                  /* current offset into display memory */
  200. extern int view_attr;                    /* current display attribute */
  201. extern int view_is_mono;                 /* flag indicates mono (TRUE) or color (FALSE) */
  202. extern int view_cols;
  203. extern int view_rows;
  204.  
  205. #define VIEW_TEXT_MODE  0                /* TRUE to treat display as \n termed text lines */
  206.  
  207. #if VIEW_HAS_RAW
  208.  
  209. #define VIEW_BIN_MODE   1                /* if TRUE display 80 column unformatted records with file offset on left */
  210. #define VIEW_HEX_MODE   2                /* if TRUE display 16 byte hex formatted display with file offset on left and ascii on right */
  211.  
  212. #endif
  213.  
  214. extern UCHAR *view_line;                 /* line input buffer */
  215.  
  216. #if VIEW_HAS_DIR
  217.  
  218. extern UCHAR *view_curdir;               /* current directory when view entered */
  219.  
  220. #endif
  221.  
  222. /*
  223.   Array of attributes for color and monochrome displays
  224. */
  225.  
  226. extern int view_attr_list[2][5];
  227.  
  228. #define ACTIVE_WINDOW     (view_attr_list[view_is_mono][0])
  229. #define INACTIVE_WINDOW   (view_attr_list[view_is_mono][1])
  230. #define ERROR_MESSAGE     (view_attr_list[view_is_mono][2])
  231. #define GET_STRING        (view_attr_list[view_is_mono][3])
  232. #define GET_STRING_CURSOR (view_attr_list[view_is_mono][4])
  233.  
  234.  
  235. /*
  236.    Function Prototypes
  237. */
  238. int max( int x, int y);
  239. int min ( int x, int y);
  240. int gcd( int a, int b );
  241.  
  242. VIEWSAVE *view_getsave( int row,int col,int rows,int cols );
  243. void view_putsave( VIEWSAVE *save );
  244. void view_restore( VIEW *trav );
  245. void view_frame( UCHAR *title,int row,int col,int rows,int cols );
  246.  
  247. void view_goto(int row,int col);
  248. void view_putc( int ochar );
  249. void view_fill(int fill, int count);
  250. void view_puts(UCHAR *str, int len);
  251. int  view_gets( int row,int col, int len, UCHAR *str);
  252. int view_prompt( UCHAR *title,UCHAR *prompt, UCHAR *retbuf, int retlen );
  253.  
  254. void _far view_errfunc();
  255. void view(void);
  256. void view_save( VIEW *trav );
  257. void view_refresh(int refresh_mode);
  258. void view_new( UCHAR *fname, int row,int col,int rows,int cols );
  259. void view_tile( void );
  260. void view_delete( void );
  261. void view_quit( void );
  262. void view_error( int isfatal, UCHAR *msg );
  263. void view_scroll( VIEW *current, int mode );
  264. UCHAR *view_strdup( UCHAR *str);
  265. int view_packbuf( UCHAR *buf, int size );
  266. void view_unpackbuf( UCHAR *buf, int row, int col, int rows, int cols );
  267.  
  268.  
  269. #if VIEW_HAS_NEWFILE
  270. int  view_newfile( void );
  271. #endif
  272.  
  273. #if VIEW_HAS_SEARCH
  274. int  view_search( void );
  275. #endif
  276.  
  277. int  view_getvidmode( void );
  278.  
  279. ULONG view_seek( VIEWFILE *vf, long pos, int base );
  280. ULONG view_tell( VIEWFILE *vf );
  281. UINT view_getl_bwd( VIEWFILE *vf, UCHAR *line, int max );
  282. UINT view_getl_fwd( VIEWFILE *vf, UCHAR *line, int max );
  283. UINT view_getc_fwd( VIEWFILE *vf );
  284. UINT view_getc_bwd( VIEWFILE *vf );
  285. int view_read_fwd( VIEWFILE *vf );
  286. int view_read_bwd( VIEWFILE *vf );
  287. VIEWFILE *view_open( UCHAR *fname );
  288. void view_close( VIEWFILE *vf );
  289.  
  290. #if VIEW_HAS_RAW
  291.  
  292. UINT view_getl_raw( VIEWFILE *vf, UCHAR *line, int dir );
  293. UCHAR *view_ultoa( ULONG num, int base, int wide, int fill );
  294.  
  295. #endif
  296.  
  297. #if VIEW_HAS_GOTO
  298.  
  299. ULONG view_atoul( UCHAR *num, int base );
  300. void view_goto_line( void );
  301.  
  302. #endif
  303.  
  304. #if VIEW_HAS_DIR
  305.  
  306. void view_dirdisp( DIRLIST *dir );
  307. int view_dir( UCHAR *name );
  308. DIRLIST *view_getlist ( void );
  309. DIRLIST *view_freelist( DIRLIST *dir );
  310. DIRLIST *view_addline(DIRLIST *dir, struct find_t *file);
  311. void view_fmtline(UCHAR *line, struct find_t *file);
  312.  
  313. #endif
  314.  
  315.